package com.ieegu.replace.controller;

import cn.hutool.core.util.StrUtil;
import com.ieegu.replace.service.ReplaceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class IndexController {

    @Autowired
    private ReplaceService replaceService;

    @RequestMapping("/")
    public String index(String content, Model model) {
        if (StrUtil.isNotBlank(content)) {
            String newStr = replaceService.doReplace(content);
            model.addAttribute("oldStr", content);
            model.addAttribute("newStr", newStr);
        }
        return "index";
    }

    @RequestMapping("/ai")
    @ResponseBody
    public String ai(String info) {
        String newStr = null;
        if (StrUtil.isNotBlank(info)) {
            newStr = replaceService.doReplace(info);
        }
        return newStr;
    }
}
